#pragma once

#include "rewine/impl/CExport.hpp"

namespace rewine
{

class CPeExport : public CExport {
private:

    bool m_IsForwarder;
    PVOID m_ExportAddress;

    WORD m_Hint;

private:

    CPeExport() = default;
    ~CPeExport() override = default;

public:

    static std::shared_ptr<CPeExport> create() {
        auto&& p = std::shared_ptr<CPeExport>(new CPeExport(), getDeleter());
        return std::move(p);
    }

public:

    void setExport(WORD index, bool bForward, PVOID va) {
        setIndex(index);
        m_IsForwarder = bForward;
        m_ExportAddress = va;
        if (!bForward) {
            setValue(va);
        }
    }

    void setName(WORD hint, PCSTR name) {
        m_Hint = hint;
        CExport::setName(std::string(name));
    }

public:

    WORD getHint() const {
        return m_Hint;
    }

    bool isForwarder() const {
        return m_IsForwarder;
    }

    std::string getForwarder() const {
        if (m_IsForwarder) {
            return std::string((PCSTR) m_ExportAddress);
        }
        return std::string();
    }

    std::string getAddressDebugString() const {
        if (m_IsForwarder) {
            return std::string("forwarder: ") + std::string((PCSTR) m_ExportAddress);
        } else {
            return std::string("address: " + std::to_string((INT_PTR) m_ExportAddress));
        }
    }

};

} // namespace rewine
